package gb;

import gb.oper.PolyOp;
import gb.struct.Monomial;
import gb.struct.Polynomial;

import java.util.*;


/**
 * 
 * @author uidl7504
 *
 */
public class PolySet implements Cloneable {
    ArrayList<Polynomial> internal;
    PolyOp operations;
    
    /**
     * 
     * @param size - how many variables characterizes a multivariate polynomial from this set
     */
    public PolySet(int size) {
        Monomial.SIZE = size;
        internal = new ArrayList<Polynomial>();
        operations = new PolyOp();
    }
    
    /**
     * 
     * @param p
     */
    public void addPoly(Polynomial p) {
        //TO DO: make some verifications here
        if (!internal.contains(p)){
            internal.add(p);
        }
    }
    
    public void removePoly(Polynomial p) {
        internal.remove(p);
    }
    
    public Polynomial getPoly(int pos) {
        return internal.get(pos);
    }
    
    public String toString() {
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i<internal.size(); i++) {
            buff.append(internal.get(i)).append("\n");
        }
        
        return buff.toString();
    } 
    
    public int size() {
        return internal.size();
    }
    
    public PolyOp getOp() {
        return operations;
    }
    
    public Object clone() {
        PolySet set = new PolySet(Monomial.SIZE);
        
        for (int i = 0; i < internal.size(); i++) {
            set.addPoly((Polynomial) internal.get(i).clone());
        }
        return set;
    }
}
